home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / passwd+ / chsh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  884 b   |  55 lines

  1. #include "passwd.h"
  2.  
  3. #ifdef GETUSERSHELL
  4. /*
  5.  * change the shell
  6.  */
  7. chsh(p)
  8. struct passwd *p;        /* pointer to password structure */
  9. {
  10.     char buf[BUFSIZ];        /* buffer for new shell */
  11.     register char *s;        /* pointer to system shells */
  12.  
  13.     /*
  14.      * display the current shell
  15.      */
  16.     printf("Changing login shell for %s.\nOld shell: %s\nNew shell: ",
  17.                             p->pw_name, p->pw_shell);
  18.     (void) fflush(stdout);
  19.  
  20.     /*
  21.      * read the response
  22.      */
  23.     if (mgets(buf, BUFSIZ, stdin) == 0 || buf[0] == '\0'){
  24.         printf("Login shell unchanged.\n");
  25.         exit(0);
  26.     }
  27.  
  28.     /*
  29.      * see if it's legal
  30.      */
  31.     while((s = GETUSERSHELL()) != NULL)
  32.         if (strcmp(s, buf) == 0)
  33.             break;
  34.  
  35.     /*
  36.      * it's not; reject it
  37.      */
  38.     if (s == NULL){
  39.         printf("%s is unacceptable as a new shell.\n", buf);
  40.         exit(0);
  41.     }
  42.  
  43.     /*
  44.      * it is -- update the record
  45.      */
  46.     p->pw_shell = s;
  47.     (void) update_pwd(p);
  48.  
  49.     /*
  50.      * bye
  51.      */
  52.     exit(0);
  53. }
  54. #endif
  55.